package com.bright.hxj.cwduijie.service.impl;

import cn.cloudlizard.jtzc.JtzcSDK;
import cn.cloudlizard.jtzc.config.AppClientConfig;
import cn.cloudlizard.jtzc.config.JtzcServerConfig;
import com.bright.hxj.cwduijie.constant.ConfigConstants;
import com.bright.hxj.cwduijie.constant.TestSendConfigConstants;
import com.bright.hxj.cwduijie.pojo.dto.QueryTaskDto;
import com.bright.hxj.cwduijie.pojo.dto.QueryTaskReturnDto;
import com.bright.hxj.cwduijie.pojo.dto.SendDataReturnDto;
import com.bright.hxj.cwduijie.pojo.dto.SendFileDto;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;

/**
 * @Author hxj
 * @Date 2025/3/27 20:31
 * @Description
 */
@Qualifier("testSend")
@Component
@Slf4j
public class TestSendWebExchangeServiceImpl extends WebExchangeServiceImpl {

    private final TestSendConfigConstants testSendConstant;

    public TestSendWebExchangeServiceImpl(ObjectMapper objectMapper, ConfigConstants constant, TestSendConfigConstants testSendConstant) {
        super(objectMapper, constant);
        this.testSendConstant = testSendConstant;
    }

    private JtzcSDK getJtzcSDK() {

//        log.debug("开始获取SDK");
        JtzcSDK sdk = new JtzcSDK(
                new JtzcServerConfig(testSendConstant.getDomain(), testSendConstant.getRootPath(), testSendConstant.getJtzcPublicKey(),
                        3 * 1000, 10 * 1000),
                new AppClientConfig(testSendConstant.getAppId(), testSendConstant.getAppSecret(), testSendConstant.getAppSecretIV(), testSendConstant.getAppPrivateKey())
        );
//        log.debug("获取SDK结束");
        return sdk;
    }

    @Override
    public SendDataReturnDto sendData(String dataString, String serviceCode) {
        return sendData(getJtzcSDK(), dataString, serviceCode);
    }

    @Override
    public SendDataReturnDto sendFile(SendFileDto sendFileDto, String serviceCode) throws IOException {
        return sendFile(getJtzcSDK(), sendFileDto, serviceCode);
    }

    @Override
    public List<QueryTaskReturnDto> queryTask(QueryTaskDto queryTaskDto) {
        return queryTask(getJtzcSDK(), queryTaskDto);
    }
}
